package com.fg.pro.trade.controller;



import com.fg.pro.model.reponse.ResponseResult;
import com.fg.pro.trade.entity.TradeCategory;
import com.fg.pro.trade.service.TradeGoodsService;
import com.github.pagehelper.PageInfo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.List;


/**
 * 商品(TradeGoods)表控制层
 *
 * @author makejava
 * @since 2025-08-12 09:18:13
 */
@Tag(name = "tradeGoods",description = "商品")
@RestController
@RequestMapping("tradeGoods")
public class TradeGoodsController {
    /**
     * 服务对象
     */
    @Resource
    private TradeGoodsService tradeGoodsService;

    @Operation(summary = "获取商品分页",description = "")
    @GetMapping("/getPage")
    public ResponseResult getPage(@RequestParam(required = false)String goodsName,
                                  @RequestParam(required = false, defaultValue = "1") Integer pageNum,
                                  @RequestParam(required = false, defaultValue = "10") Integer pageSize){
        PageInfo pageInfo = tradeGoodsService.getPage(pageNum,pageSize,goodsName);
        return ResponseResult.okResult(pageInfo);
    }

    @Operation(summary = "刷新商品",description = "参数时间，可以不传参，默认刷新时间当前")
    @PostMapping("/refresh")
    public ResponseResult refresh(@RequestParam(required = false) @DateTimeFormat(pattern = "yyyy-MM-dd") Date date) throws InterruptedException {
        boolean flag = tradeGoodsService.refresh(date);
        return ResponseResult.okResult(flag?"刷新成功":"正在刷新中。。。");
    }


}

